package com.geekstudy.week4.thread;

import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

public class ThreadDemoMain {

    public static void test1() {
        ThreadDemo1 demo1 = new ThreadDemo1();
        demo1.start();
        System.out.println("主线程 调用 ThreadDemo1 ");

        ThreadDemo2 demo2 = new ThreadDemo2();
        demo2.start();
        System.out.println("主线程 调用 ThreadDemo2 ");

        ThreadCallable threadCallable = new ThreadCallable();
        FutureTask<String> futureTask = new FutureTask<String>(threadCallable);
        new Thread(futureTask).start();
        System.out.println("主线程 调用 ThreadCallable ");
        try {
            System.out.println("主线程 调用 ThreadCallable 返回值:" + futureTask.get());
        } catch(Exception e) {
            e.printStackTrace();
        }

    }

    public static void test2() {
        ThreadDemo2 demo2 = new ThreadDemo2();
        for(int size = 0; size < 5; size++) {
            new Thread(demo2, "线程ThreadDemo2-[" + size + "]").start();
        }
        try {
            Thread.sleep(10000);
        } catch(Exception e) {
            e.printStackTrace();
        }

        printCurrentThread();
    }

    public static void printCurrentThread() {
        Thread currentThread = Thread.currentThread();
        System.out.println("当前线程 "
                + " 活跃线程数:" + Thread.activeCount()
                + " 名称:" + currentThread.getName()
                + " 标识符:" + currentThread.getId()
                + " 优先级:" + currentThread.getPriority()
                + " 状态:" + currentThread.getState()
                + " 线程组:" + currentThread.getThreadGroup()
                + " 是否守护线程:" + currentThread.isDaemon());
    }

    public static void main(String[] args) {

        // test1();

        test2();




    }


}
